<?
error_reporting(0);
session_start();
header('Content-Type: image/png');
//生成验证码图片
$img = imagecreate(50,20);
$back = imagecolorallocate($img, 245,245,245);
imagefill($img,0,0,$back); //背景
srand((double)microtime()*1000000);
//生成4位数字
$imgstr = '0123456789ABCDEFGHIJKLMNPQRSTUVWXYZ';
for($i = 0;$i<4;$i++){
	$font = imagecolorallocate($img, rand(100,255),rand(0,100),rand(100,255));
	$authNum = substr($imgstr, rand(0, 34),1);
	$vcodes .= $authNum;
	imagestring($img, 5, 2+$i*12, 3, $authNum, $font);
}
for($i = 0;$i<100;$i++) //加入干扰象素
{ 
	$randcolor = imagecolorallocate($img,rand(0,255),rand(0,255),rand(0,255));
	imagesetpixel($img, rand()%50 , rand()%20 , $randcolor);
} 
imagepng($img);
imagedestroy($img);
$_SESSION['ImgCode'] = $vcodes;
?>